import request from "../utils/request";
export interface IUserParams {
  username: string;
  password: string;
  avatar: string;
}
//登录
export const userLogin = (params: IUserParams) => {
  return request.post("/login", params);
};

export interface ICollectParams {
  userid: string;
  courseid: string;
  name: string;
  poster: string;
  isvip: boolean;
  info: string;
}
//收藏
export const userCollect = (params: ICollectParams) => {
  return request.post("/classes/ReactCollect", params);
};

// 查询收藏表
export interface ICollectSearchParams {
  userid: string | undefined;
  courseid?: string;
}
export const userCollectGet = (params: ICollectSearchParams) => {
  let search = JSON.stringify(params);
  return request.get(`/classes/ReactCollect?where=${search}`);
};

// 移除收藏
// 需要携带什么条件？ 收藏表的唯一id
export const userCollectDel = (collectid: string) => {
  return request.delete(`/classes/ReactCollect/${collectid}`);
};

//更新用户信息
interface IUserUpdateParams {
  avatar: string;
}
export const userUpdate = (
  objectId: string,
  token: string,
  params: IUserUpdateParams
) => {
  // return request.put(`/users/${objectId}`, params);
  return request({
    url: `/users/${objectId}`,
    method: "PUT",
    headers: {
      "X-LC-Session": token,
    },
    data: params,
  });
};
